home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / music / dsik_pas.zip / EXAM2.PAS < prev    next >
Pascal/Delphi Source File  |  1994-07-28  |  3KB  |  87 lines

  1. (*  exam3.pas - Digital Sound Interface Kit V1.01a example code
  2.  
  3.     Copyright 1993,94 Carlos Hasan
  4. *)
  5.  
  6. program Example3;
  7. uses Crt,Sound,Load,TS;
  8.  
  9. const
  10.   PeriodTable : array [1..12*4] of word =
  11.     { C   C#  D   D#  E   F   F#  G   G#  A   A#  B }
  12.     ( 856,808,762,720,678,640,604,570,538,508,480,453,
  13.       428,404,381,360,339,320,302,285,269,254,240,226,
  14.       214,202,190,180,170,160,151,143,135,127,120,113,
  15.       107,101,95,90,85,80,75,71,67,63,60,56 );
  16.  
  17.   KeyTable : array [1..12*3] of char =
  18.       'ZSXDCVGBHNJMQ2W3ER5T6Y7UI9O0P';
  19.  
  20. var
  21.   Card   : DSMCard;
  22.   Sample : PDSMInst;
  23.   Key    : Char;
  24.   Note   : Integer;
  25.   Chan   : Integer;
  26. begin
  27.   if DSMLoadSetup(Card) then begin
  28.     writeln('Please run SETUP.EXE to configure.');
  29.     exit;
  30.   end;
  31.   if DSMInit(Card) then begin
  32.     writeln('Error Initializing the Sound System.');
  33.     exit;
  34.   end;
  35.   Sample := DSMLoadSample('DING.WAV',0);
  36.   if Sample = nil then begin
  37.     case DSMStatus of
  38.       ERR_NORAM:  writeln('Not enough system memory.');
  39.       ERR_NODRAM: writeln('Not enough card memory.');
  40.       ERR_NOFILE: writeln('File not found.');
  41.       ERR_FORMAT: writeln('Invalid file format.');
  42.       ERR_ACCESS: writeln('File damaged.');
  43.     end;
  44.     DSMDone;
  45.     exit;
  46.   end;
  47.   DSMSetupVoices(9,128);
  48.  
  49.   TSInit;
  50.   TSSetRate(70);
  51.   TSSetRoutine(DSMPoll);
  52.  
  53.   writeln;
  54.   writeln('     C# D#    F# G# A#    C# D#    F# G# A#    C# D#   ');
  55.   writeln('  │ │ ││ │ │ │ ││ ││ │ │ │ ││ │ │ │ ││ ││ │ │ │ ││ │ │ ');
  56.   writeln('  │ │ ││ │ │ │ ││ ││ │ │ │ ││ │ │ │ ││ ││ │ │ │ ││ │ │ ');
  57.   writeln('  │ │S││D│ │ │G││H││J│ │ │2││3│ │ │5││6││7│ │ │9││0│ │ ');
  58.   writeln('  │ └┬┘└┬┘ │ └┬┘└┬┘└┬┘ │ └┬┘└┬┘ │ └┬┘└┬┘└┬┘ │ └┬┘└┬┘ │ ');
  59.   writeln('  │ Z│ X│ C│ V│ B│ N│ M│ Q│ W│ E│ R│ T│ Y│ U│ I│ O│ P│ ');
  60.   writeln('  └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘ ');
  61.   writeln('    C  D  E  F  G  A  B  C  D  E  F  G  A  B  C  D  E  ');
  62.   writeln;
  63.   writeln('    Press keys to play the sample and ESC to exit.     ');
  64.  
  65.   Chan := 0;
  66.   repeat
  67.     Key := UpCase(ReadKey);
  68.     for Note := 1 to 12*3 do
  69.       if Key = KeyTable[Note] then begin
  70.         { play chord C-E-G }
  71.         DSMPlaySample(Chan,Sample);
  72.         DSMPlaySample(Chan+1,Sample);
  73.         DSMPlaySample(Chan+2,Sample);
  74.         DSMSetPeriod(Chan,PeriodTable[Note]);
  75.         DSMSetPeriod(Chan+1,PeriodTable[Note+4]);
  76.         DSMSetPeriod(Chan+2,PeriodTable[Note+7]);
  77.         Chan := (Chan+3) mod 9;
  78.       end;
  79.   until Key = #27;
  80.  
  81.   TSDone;
  82.   TSRestoreTime;
  83.  
  84.   DSMFreeSample(Sample);
  85.   DSMDone;
  86. end.
  87.